#include <iostream>
#include <algorithm>
using namespace std;
int m;
int safe[100010];
int result[100010];

int predict(int theta, int y)
{
    if (y < theta)
        return 0;
    else
        return 1;
}

int getcnt(int theta)
{
    int count = 0;
    for (int i = 1; i <= m; i++)
    {
        if (predict(theta, safe[i]) == result[i])
            count++;
    }
    return count;
}

int main()
{
    int count = 0, best = 0;
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> safe[i] >> result[i];
    }
    for (int i = 1; i <= m; i++)
    {
        int temp = getcnt(safe[i]);
        if (temp > count)
        {
            count = temp;
            best = safe[i];
        }
        else if (temp == count)
        {
            best = max(best, safe[i]);
        }
        else
        {
            continue;
        }
    }
    cout << best << endl;
    //system("pause");
}